package com.wyd.decorate.demo01;

import com.wyd.decorate.demo01.Beverage.Beverage;
import com.wyd.decorate.demo01.Beverage.DarkRoast;
import com.wyd.decorate.demo01.Condiment.Milk;
import com.wyd.decorate.demo01.Condiment.Mocha;
import com.wyd.decorate.demo01.Condiment.Whip;

/**
 * 装饰者模式
 * 被装饰者与装饰者据有相同的接口，如此才能进行包装而采用相同的引用类型
 * 向装饰者中传入被装饰者，在执行被装饰者方法的前后执行装饰代码
 *
 * @author Yudi Wang
 * @date 2022/1/6 15:39
 */
public class main {
    public static void main(String[] args) {
        Beverage beverage = new DarkRoast();
        //用装饰者 将 被装饰者进行包装，并暴露相同的接口
        beverage = new Milk(beverage);
        beverage = new Mocha(beverage);
        beverage = new Whip(beverage);

        System.out.println("咖啡清单：" + beverage.getDescription());
        System.out.println("咖啡价格：" + beverage.cost());
    }
}
